package com.ruoyi.industryfrontend.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.web.page.TableDataList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.industryfrontend.domain.ProjectPark;
import com.ruoyi.industryfrontend.service.IProjectParkService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 我的园区Controller
 *
 * @author MagicCube
 * @date 2023-05-30
 */
@RestController
@RequestMapping("/park")
public class ProjectParkController extends BaseController
{
    @Autowired
    private IProjectParkService projectParkService;

    /**
     * 查询我的园区列表
     */
    @RequiresPermissions("myIndustry:park:list")
    @GetMapping("/list")
    public TableDataInfo list(ProjectPark projectPark)
    {
        startPage();
        List<ProjectPark> list = projectParkService.selectProjectParkList(projectPark);
        return getDataTable(list);
    }
    @RequiresPermissions("myIndustry:park:list")
    @GetMapping("/parkList")
    public TableDataList parkList(ProjectPark projectPark)
    {
        startPage();
        List<ProjectPark> list = projectParkService.selectProjectParkList(projectPark);
        return getDataList(list);
    }

    /**
     * 导出我的园区列表
     */
    @RequiresPermissions("myIndustry:park:export")
    @Log(title = "我的园区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectPark projectPark)
    {
        List<ProjectPark> list = projectParkService.selectProjectParkList(projectPark);
        ExcelUtil<ProjectPark> util = new ExcelUtil<ProjectPark>(ProjectPark.class);
        util.exportExcel(response, list, "我的园区数据");
    }

    /**
     * 获取我的园区详细信息
     */
    @RequiresPermissions("myIndustry:park:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectParkService.selectProjectParkById(id));
    }

    /**
     * 新增我的园区
     */
    @RequiresPermissions("myIndustry:park:add")
    @Log(title = "我的园区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectPark projectPark)
    {
        return toAjax(projectParkService.insertProjectPark(projectPark));
    }

    /**
     * 修改我的园区
     */
    @RequiresPermissions("myIndustry:park:edit")
    @Log(title = "我的园区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectPark projectPark)
    {
        return toAjax(projectParkService.updateProjectPark(projectPark));
    }

    /**
     * 删除我的园区
     */
    @RequiresPermissions("myIndustry:park:remove")
    @Log(title = "我的园区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(projectParkService.deleteProjectParkById(id));
    }
}
